def-grammar name element definition &rest elements definitions
def-grammar defines a grammar for a song, or a melody, and is normally used with the Class System. As it performs defsym definition for each element it can be used as a replacement of defsym when non-evaluated definitions are needed.
(def-grammar 'structure
song (intro middle ending)
intro (a b)
middle (am bm cm bm)
ending (ae be)
)
The grammar is expanded with expand-grammar.
(expand-grammar song 2 'structure)
--> (a a am bm cm bm ae be)
The grammar can be of the following types:
• determined non-recursive
(def-grammar 'structure
song (intro middle ending)
intro (a b)
middle (am bm cm bm)
ending (ae be)
)
• non-determined non-recursive
(def-grammar 'structure
song (intro middle ending)
intro (a b)
intro (c d) ; double definition
middle (am bm cm bm)
ending (ae be)
)
• non-determined recursive
(def-grammar 'structure
song (intro middle ending)
intro (a intro b) ; element defined directly by itself
middle (am bm cm bm)
ending (ae be song) ; or indirectly
)
• determined non-recursive
(def-grammar 'structure
song (intro middle ending)
intro (a intro b) ; multiple recursive definitions
intro (a b intro)
middle (am bm cm bm)
ending (ae be song)
ending (ae song be)
)
def-grammar and defsym have a close relation. The following definitions are equal.
(def-grammar 'structure
song (intro ending)
intro (a b)
ending (c d)
)
(initdef 'structure)
(defsym song '(intro ending) :tree 'structure)
(defsym intro '(a b) :tree 'structure)
(defsym ending '(c d) :tree 'structure)
You can define as many grammars as needed to handle different aspects of the composition. With the Class System you'll be able to use multiple parallel grammars to control the composition formation.